package com.situation.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situation.mapper.BizSupplierMapper;
import com.situation.pojo.DO.BizSupplier;
import com.situation.service.BizSupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Service
public class BizSupplierServiceImp implements BizSupplierService {

    @Autowired
    private BizSupplierMapper bizSupplierMapper;

    @Override
    public int add(BizSupplier supplier) {
        supplier.setCreateTime(LocalDateTime.now());
        supplier.setModifiedTime(LocalDateTime.now());
        return bizSupplierMapper.add(supplier);
    }

    @Override
    public BizSupplier insert(BizSupplier supplier) {
        supplier.setCreateTime(LocalDateTime.now());
        supplier.setModifiedTime(LocalDateTime.now());
        bizSupplierMapper.add(supplier);
        return supplier;
    }

    @Override
    public int delete(long id) {
        return bizSupplierMapper.delete(id);
    }

    @Override
    public BizSupplier selectSupplierById(long id) {
        return bizSupplierMapper.selectSupplierById(id);
    }

    @Override
    public PageInfo<BizSupplier> findAll() {
        PageHelper.startPage(1,10);
        List<BizSupplier> supplierList = bizSupplierMapper.findAll();
        return new PageInfo<>(supplierList);
    }

    @Override
    public PageInfo<BizSupplier> findSupplierList(BizSupplier bizSupplier,int pageNum,int size) {
        PageHelper.startPage(pageNum,size);
        List<BizSupplier> supplierList = bizSupplierMapper.findSupplierList(bizSupplier);
        return new PageInfo<>(supplierList);
    }

    @Override
    public int update(BizSupplier bizSupplier) {
        return bizSupplierMapper.update(bizSupplier);
    }
}
